package com.starmark.gateway.springcloud.provider.service.impl;

import com.starmark.gateway.springcloud.provider.service.ICacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 缓存类,后续考虑用分布式缓存
 * @author starmark
 * @date 2020/5/6  下午8:31
 */
@Service
public class CacheServiceImpl  implements ICacheService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public String getCacheByKey(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }


    @Override
    public List<String> getCacheListByKeys(Set<String> keys) {
        return stringRedisTemplate.opsForValue().multiGet(keys);
    }

    @Override
    public Map<Object, Object> getMapByKey(String key) {
        return stringRedisTemplate.opsForHash().entries(key);
    }

    @Override
    public Set<String> getCacheKeysByKey(String key) {
        return  stringRedisTemplate.keys(key);
    }
}
